﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Card.Utility
{
    public class TextUtility
    {
        /// <summary>
        /// 截取字符串
        /// </summary>
        /// <param name="str"></param>
        /// <param name="length"></param>
        /// <param name="suffix"></param>
        /// <returns></returns>
        public static string Cut(string str, int length, string suffix)
        {
            if (str.Length < length)
            {
                return string.Format("{0}{1}", str.Substring(0, length), suffix);
            }

            return str;
        }
        /// <summary>
        /// 解码js unescape
        /// </summary>
        /// <param name="val"></param>
        /// <returns></returns>
        public static string JSUnescape(string val)
        {
            return Microsoft.JScript.GlobalObject.unescape(val);
        }
        /// <summary>
        /// 编码 escape
        /// </summary>
        /// <param name="val"></param>
        /// <returns></returns>
        public static string JSEscape(string val)
        {
            return Microsoft.JScript.GlobalObject.escape(val);
        }
    }
}
